package org.demo.tools;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

import com.google.common.collect.Ordering;


public class SortTest {

	public static void main(String[] args) {
		List<RankVo> list = new ArrayList<RankVo>();
		RankVo rv = new RankVo();
		rv.setScore(100);
		list.add(rv);
		RankVo rv1 = new RankVo();
		rv1.setScore(100);
		list.add(rv1);
		RankVo rv2 = new RankVo();
		rv2.setScore(80);
		list.add(rv2);
		 rv2 = new RankVo();
		rv2.setScore(80);
		list.add(rv2);
		 rv2 = new RankVo();
		rv2.setScore(70);
		list.add(rv2);
		 rv2 = new RankVo();
		rv2.setScore(80);
		list.add(rv2);
		
		
		
		 Comparator<RankVo> userComparator = Ordering.from(new Comparator<RankVo>() {
			@Override
			public int compare(RankVo o1, RankVo o2) {
				return o2.getScore().compareTo(o1.getScore());
			}
		});
		 Collections.sort(list, userComparator);
		
		 int rank = 1;
		 int score = 0;
		 int sort = 1;
		 for(int i =0;i<list.size();i++){
			 RankVo vo = (RankVo)list.get(i);
			 if(i==0){
				 score = vo.getScore();
				 vo.setRanking(rank);
				 continue;
			 }
			 
			 if(vo.getScore().intValue()== score){
				 vo.setRanking(rank);
				 sort++;
			 }else{
				 sort++;
				 rank = sort;
				 vo.setRanking(rank);
				
			 }
			 score = vo.getScore();
		 }
		 
		 for(RankVo rvo : list){
			 System.out.println(rvo.getScore() +":"+rvo.getRanking());
		 }
		
		 
	}
	


}

	class RankVo {
	Integer score;
	Integer ranking;
	public Integer getScore() {
		return score;
	}
	public void setScore(Integer score) {
		this.score = score;
	}
	public Integer getRanking() {
		return ranking;
	}
	public void setRanking(Integer ranking) {
		this.ranking = ranking;
	}
}
